#ifndef TRANSFORMERCONTENT_DEFAULTSETTINGS_3
#define TRANSFORMERCONTENT_DEFAULTSETTINGS_3

#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>

class TransContentSetting{
	private:
		static int logFlushInterval;

		///buffer size, the range defined in define 
		static int memoryBufferSize;

		///buffer count, the range defined in define
		static int memoryBufferCount;
		
		static int threadPoolThreadsCount;
		
		static NodeAddr localAddr;
		
		static int contentTimrInterval;
		
		///localFifo name is app directory sub directory ./data/dataStream
		static char localFifoFileName[FILE_NAME_LEN];
		
		static char localDataParent[FILE_NAME_LEN];
		
		static char pids[16];
		
		static int allPortCount;
	public:
		static void setLogFlushInterVal(int interval){
			if(interval < LOGGER_FLUSH_INTERVAL_MIN || interval > LOGGER_FLUSH_INTERVAL_MAX){
				return;
			}
			logFlushInterval = interval;
		}

		static int getLogFlushInterVal(){
			return logFlushInterval;
		}

		static void setMemoryBufferSize(int bufferSize){
			if(bufferSize < MEMORY_RECORD_MIN_SIZE || bufferSize > MEMORY_RECORD_MAX_SIZE)
				return;
			memoryBufferSize = bufferSize;
		}

		static int getMemoryBufferSize(){
			return memoryBufferSize;			
		}

		static void setMemoryBufferCount(int count){
			if(count < MEMORY_RECORD_MIN_COUNT || count > MEMORY_RECORD_MAX_COUNT)
				return;
			memoryBufferCount = count;
		}

		static int getMemoryBufferCount(){
			return memoryBufferCount;
		}

		static NodeAddr getInvalidateAddr(){
			NodeAddr _tempAddr;
			_tempAddr.serial_id = -1;
			return _tempAddr;
		}
		
		static void setThreadPoolThreadsCount(int count){
			if(count < THREADS_COUNT_MIN || count > THREADS_COUNT_MAX)
				return;
			threadPoolThreadsCount = count;			
		}
		
		static void setLocalAddr(const NodeAddr* nodeAddr){
			localAddr.serial_id = nodeAddr->serial_id;
		}
	
		///////////////////////////////////////////////
		/// just return the localAddr to caller thread
		///
		/// notice:
		///		after the function reutrn, should judge the return value, if a vaildate one,
		///		should call getStackInfo class to get a localAddr
		///////////////////////////////////////////////
		static NodeAddr getLocalAddr(){
			return localAddr;
		}
		
		static NodeAddr getLocalAddrNetBytes(){
			NodeAddr _tempAddr = localAddr;
			_tempAddr.half_value[0] = ntohl(_tempAddr.half_value[0]);
			_tempAddr.half_value[1] = ntohl(_tempAddr.half_value[1]);
			return _tempAddr;
		}

		static const char* getProcessId() {
			if(pids[0] == 0){
				sprintf(pids, "%d", getpid());
				sprintf(localDataParent, "/data/data/vrouteDatas/client/%s", pids);
			}
			return pids;
		}
		
		static void setContentTimerInterval(int second){
			if(second > CONTENT_TIMER_INTERVAL_MAX || second < CONTENT_TIMER_INTERVAL_MIN)
				return;
			contentTimrInterval = second;
		}
		
		static int getContentTimerInterval(){
			return contentTimrInterval;
		}
		
		static void setLocalDirectory(const char* dir){
			memset(localFifoFileName, 0x00, FILE_NAME_LEN);
			snprintf(localFifoFileName,FILE_NAME_LEN,"%s/data/dataStream", dir);			
		}
		
		static const char* getLocalFifoName(){
			return localFifoFileName;
		}
		
		static int getAllPortCount(){
			return allPortCount;
		}
		
		static void setAllPortCount(int count){
			if(allPortCount > ALLPORT_COUNT_MAX || allPortCount < ALLPORT_COUNT_MIN){
				return;
			}
			allPortCount = count;
		}
		
		static int getRandomInt(){
			srand((int)time(NULL));
			return random();
		}

		static void getTimeStr(char* buffer, int len){
			time_t timer = time(NULL);
			strftime(buffer, len, "%Y-%m-%d %H:%M:%S", localtime(&timer));
		}

		////////////////////////////////////////////////////
		/// /path/2013-3-17-20-00-00-00
		///////////////////////////////////////////////////
		static int getDumpPacketFileName(char* path, int len){
			time_t tt;
			time(&tt);
			tm dt = localtime(&tt);
			sprintf(path, "/data/data/vrouteDatas/client/dumps/%d-%d-%d-%d-%d-%d.dump", dt.tm_year, dt.tm_mon , dt.tm_mday, dt.tm_hour, dt.tm_min, dt.tm_sec); 
			return 0;
		}
};

int TransContentSetting::logFlushInterval = LOGGER_FLUSH_INTERVAL_DEFAULT;
int TransContentSetting::memoryBufferSize = MEMORY_RECORD_DEFOUT_SIZE;
int TransContentSetting::memoryBufferCount = MEMORY_RECORD_DEFOUT_COUNT;
int TransContentSetting::threadPoolThreadsCount = THREADS_COUNT_DEFAULT;
NodeAddr TransContentSetting::localAddr = {-1};
int TransContentSetting::contentTimrInterval = CONTENT_TIMER_INTERVAL_DEFAULT;
int TransContentSetting::allPortCount = ALLPORT_COUNT_DEFAULT;
char TransContentSetting::pids[16] = {0};
char TransContentSetting::localDataParent[FILE_NAME_LEN] = {0};
#endif //TRANSFORMERCONTENT_DEFAULTSETTINGS_3
